<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>

<div class="layui-fluid" id="app" style="margin-top: 0px">

    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">

            <div class="layui-card">

                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li onclick="go('selectdp')">店铺</li>
                            <li onclick="go('newdp')" class="layui-this">新增店铺</li>

                        </ul>

                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">

                            <div class="layui-tab-item layui-show">

                                <form class="layui-form" action="" lay-filter="component-form-group">
                                    <!--<div class="layui-card-header">表单组合</div>-->
                                    <div class="layui-card-body" style="padding: 15px;">

                                        <div class="layui-form-item">
                                            <label class="layui-form-label">手机号</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="phone" lay-verify="required|phone|number"
                                                       autocomplete="off"
                                                       id="phone"
                                                       placeholder="请输入 手机号将作为等录账号"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-form-item">
                                            <label class="layui-form-label">店长</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="biz[dianzhang]" lay-verify="required"
                                                       autocomplete="off"
                                                       id="dianzhang"
                                                       placeholder="请输入 "
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-form-item">
                                            <label class="layui-form-label">密码</label>
                                            <div class="layui-input-block">
                                                <input type="password" name="password" lay-verify="required"
                                                       placeholder="请输入"
                                                       autocomplete="off"
                                                       class="layui-input">
                                            </div>
                                        </div>

                                        <div class="layui-form-item">
                                            <label class="layui-form-label">重复密码</label>
                                            <div class="layui-input-block">
                                                <input type="password" name="repassword" lay-verify="required"
                                                       placeholder="重复密码"
                                                       autocomplete="off"
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-form-item">
                                            <label class="layui-form-label">店名</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="biz[shop_name]" lay-verify="required"
                                                       autocomplete="off"
                                                       id="shop_name"
                                                       placeholder="请输入 "
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-form-item">
                                            <label class="layui-form-label">店铺图片</label>

                                            <div class="layui-input-inline " style="width: auto;">

                                                <div class="layui-upload-drag" id="pic1" style="padding: 2px">
                                                    <img class="layui-upload-img"
                                                         style="width: auto;height: 120px; object-fit: cover;"
                                                         src="/res/img/thumb.png" id="im">
                                                    <input type="hidden" name="biz[shop_logo]" value="">
                                                </div>


                                                <!--<div class="layui-btn layui-btn-primary" id="test10">-->
                                                <!--<i class="layui-icon">点击上传</i>-->
                                                <!--&lt;!&ndash;<p>点击上传</p>&ndash;&gt;-->
                                                <!--</div>-->


                                            </div>
                                        </div>


                                        <div class="layui-form-item">
                                            <label class="layui-form-label">区域</label>
                                            <div class="layui-input-inline">
                                                <select name="biz[sheng]" lay-verify="required">
                                                    <!--<option value="">请选择省</option>-->
                                                    <option value="河南省" selected="">河南省</option>
                                                </select>
                                            </div>
                                            <div class="layui-input-inline">
                                                <select name="biz[shi]" lay-verify="required">
                                                    <!--<option value="">请选择市</option>-->
                                                    <option value="周口市">周口市</option>
                                                </select>
                                            </div>
                                            <div class="layui-input-inline">
                                                <select name="biz[xian]" lay-verify="required">
                                                    <!--<option value="">请选择县/区</option>-->
                                                    <option value="川汇区">川汇区</option>
                                                    <option value="东新区">东新区</option>

                                                </select>
                                            </div>
                                        </div>


                                        <div class="layui-form-item">
                                            <label class="layui-form-label">详细地址</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="biz[address]" lay-verify="required"
                                                       autocomplete="off"
                                                       id="address"
                                                       placeholder="请输入 "
                                                       class="layui-input">
                                            </div>
                                        </div>


                                        <div class="layui-form-item">
                                            <label class="layui-form-label">状态</label>
                                            <div class="layui-input-block">
                                                <input type="radio" name="status" value="1" title="正常" checked="">
                                                <input type="radio" name="status" value="0" title="禁用">

                                            </div>
                                        </div>


                                    </div>

                                    <div class="layui-card-footer" style="padding: 15px;">
                                        <div class="layui-form-item">
                                            <div class="layui-input-block">
                                                <div class="layui-footer">
                                                    <button class="layui-btn" lay-submit=""
                                                            lay-filter="component-form-demo1">立即提交
                                                    </button>
                                                    <button type="reset" class="layui-btn layui-btn-primary" onclick="restart()">重置</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>

                    </div>
                </div>


            </div>
        </div>
    </div>

    <script>


        layui.use(['form', 'laydate', 'upload'], function () {
            var $ = layui.$
                , element = layui.element
                , layer = layui.layer
                , laydate = layui.laydate
                , form = layui.form;
            var upload = layui.upload;

            form.render(null, 'component-form-group');

            laydate.render({
                elem: '#LAY-component-form-group-date'
            });

            /* 自定义验证规则 */
            form.verify({
                title: function (value) {
//      if(value.length < 5){
//        return '标题至少得5个字符啊';
//      }
                }
                , pass: [/(.+){6,12}$/, '密码必须6到12位']
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });


            form.on('checkbox(test)', function (data) {
//                console.log(data.elem); //得到checkbox原始DOM对象
                console.log(data.elem.checked); //是否被选中，true或者false
//                console.log(data.value); //复选框value值，也可以通过data.elem.value得到
//                console.log(data.othis); //得到美化后的DOM对象
                if ($(data.elem).attr('name') == 'identity[worker]' && data.elem.checked) {
//                    console.log(11111);
                    $('#worker').fadeIn();
                } else if ($(data.elem).attr('name') == 'identity[worker]' && !data.elem.checked) {
//                    console.log(22222);
                    $('#worker').hide();
                }


            });

            //拖拽上传
            upload.render({
                elem: '#pic1'
                , url: '/tool/qiniu/upload'
                , before: function () {
                    layer.load(2);
                }
                , done: function (res) {
                    layer.closeAll();
                    console.log(res)
                    $('#pic1 img').attr('src', res.data.url);
                    $('#pic1 input').val(res.data.pic);
                }
            });


            /* 监听提交 */
            form.on('submit(component-form-demo1)', function (data) {

                $.post("{:url('newdp')}", data.field, function (res) {
                    if (res.code == 1) {
                        parent.layer.msg(res.msg, {icon: 1})
                        //将数据传入到父元素
//                        parent.app.items.push(data.field);
//                        $('.layui-form')[0].reset();
                        $('#phone').val('');
                        $('#dianzhang').val('');
                        $('#shop_name').val('');
                        $('#address').val('');
                        var pic='/res/img/thumb.png';
                        $('#pic1 img').attr('src', pic);
                        var id=res.data.uid;
                        var name=res.data.shop_name;
                        // console.log(id);
                        // console.log(name);
                        parent.dianpu(id,name);
                        parent.layer.closeAll();
                        return false;
                    } else {
                        parent.layer.msg(res.msg, {icon: 2})
                        return false;
                    }
                });


                return false;
            });
        });
        //重新选择图片
        function restart(){
            $('#im').attr('src','/res/img/thumb.png');
        }
    </script>
</div>
</body>
</html>










